<?php
namespace App\Http\Controllers\Business;

use App\Models\User;
use App\Models\WaterMeter;
use App\Models\WaterMeterRadix;
use App\Models\WaterMeterDayConsumption;
use Illuminate\Support\Facades\Auth;

class StatisticModule {
    //首页
    public static function index() {
        //总的区域
        $enterpriseCount = WaterMeter::where('status', 1)->groupBy('enterprise_name')->pluck('enterprise_name')->count();
        //水表个数
        $waterMeterCount = WaterMeter::where('status', 1)->count();
        //水量
        $consumption = WaterMeterDayConsumption::where('watermeter_day_consumption.current_date', date('Y-m-d', strtotime("-1days")))
                ->join('watermeters', 'watermeters.number', '=', 'watermeter_day_consumption.number')
                ->where('watermeters.node_level', 1)
                ->sum('watermeter_day_consumption.consumption');
        if($consumption == 0) {
            $consumption = 0;
        }
        //昨天上传数据水表个数
        $yesterdayReportedDataWaterMeterCount = WaterMeter::where('status', 0)->where('last_time', '>=', date('Y-m-d', strtotime('-1days')))->count();
        $lngAndLatList = json_encode([
            ['longitude'=>115.953115, 'latitude'=>28.674775],
            ['longitude'=>115.953053, 'latitude'=>28.675979],
        ]);
        $data = [
            'enterprise_count' => $enterpriseCount,
            'watermeter_count' => $waterMeterCount,
            'consumption' => $consumption,
            'yesterday_reported_data_watermeter_count' => $yesterdayReportedDataWaterMeterCount,
            'lng_and_lat_list' => $lngAndLatList
        ];
        return ['status'=>'success', 'data'=>$data];
    }
}
?>
